package com.example.servicelocation;

import android.location.Location;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.recyclerview.widget.RecyclerView;

import java.util.ArrayList;

public class MyAdapter extends RecyclerView.Adapter<MyAdapter.MyViewHolder> {
    private ArrayList<Location> mDataset;
    public static class MyViewHolder extends RecyclerView.ViewHolder {
        public TextView num;
        public TextView lat;
        public TextView lng;
        public TextView type;
        public TextView acc;
        public MyViewHolder(View v) {
            super(v);
            num = v.findViewById(R.id.num);
            lat = v.findViewById(R.id.lat);
            lng = v.findViewById(R.id.lng);
            type = v.findViewById(R.id.type);
            acc = v.findViewById(R.id.acc);
        }
    }

    public MyAdapter(ArrayList<Location> myDataset) {
        mDataset = myDataset;
    }

    @Override
    public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View v = LayoutInflater.from(parent.getContext())
                .inflate(R.layout.row_text, parent, false);
        MyViewHolder vh = new MyViewHolder(v);
        return vh;
    }

    @Override
    public void onBindViewHolder(MyViewHolder holder, int position) {
        Location location=mDataset.get(position);
        holder.num.setText(String.valueOf(position));
        holder.lat.setText(String.valueOf(location.getLatitude()));
        holder.lng.setText(String.valueOf(location.getLongitude()));
        holder.acc.setText(String.valueOf(location.getAccuracy()));
        holder.type.setText(location.getProvider());
    }

    @Override
    public int getItemCount() {
        return mDataset.size();
    }


}
